package com.admin.discountService.controller;


import com.admin.discountService.pojo.MobileEndDiscount;
import com.admin.discountService.service.MobileEndDiscountService;
import com.admin.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 折扣表 前端控制器
 * </p>
 *
 * @author wang-chao-wen
 * @since 2022-12-13
 */
@RestController
@RequestMapping("discount")
public class MobileEndDiscountController {
    @Autowired
    private MobileEndDiscountService discountService;
    /**
     * 根据用户id或者转态查询数据
     * @param userId
     * @param state
     * @return
     */
    @RequestMapping("getByUserIdAndState")
    public R findData(@RequestParam("userId") String userId,@RequestParam("state") String state){
        QueryWrapper<MobileEndDiscount> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId",userId).eq("state",state);
        List<MobileEndDiscount> list = discountService.list(queryWrapper);
        System.out.println("list:"+list);
        if(list == null || list.size() == 0){
            return R.error();
        }
        return R.ok().data("items",list);
    }


}

